
//格式化日期：yyyy-MM-dd 
function formatDate(date) {
    var myyear = date.getFullYear();
    var mymonth = date.getMonth()+1;
    var myweekday = date.getDate();

    if(mymonth < 10){
        mymonth = "0" + mymonth;
    }
    if(myweekday < 10){
        myweekday = "0" + myweekday;
    }
    return (myyear+"-"+mymonth + "-" + myweekday);
}


function getWeekStartDateAndEndDateRange() {
    var oneDayLong = 24*60*60*1000 ;
    var now = new Date();
    var mondayTime = now.getTime() - (now.getDay()-1)*oneDayLong;
    var sundayTime = now.getTime() + (7-now.getDay())*oneDayLong;
    var monday = new Date(mondayTime);
    var sunday = new Date(sundayTime);
    var weekRange = [monday, sunday];
    return weekRange;
}

function getAfterDay(n){
    var date = new Date();
    date.setDate(date.getDate() + n);
    return formatDate(date) +" 00:00:00";
}
/**
 *获得本月的开始日期和结束日期
 */
function getMonthStartDateAndDateRange() {
    var oneDayLong = 24*60*60*1000;
    var now = new Date();
    var year = now.getFullYear();
    var monthStartDate = new Date(year, now.getMonth(), 1);//当前月1号
    var nextMonthStartDate = new Date(year, now.getMonth()+1, 1);//下个月1号
    var days = (nextMonthStartDate.getTime() -
        monthStartDate.getTime())/oneDayLong;//计算当前月份的天数
    var monthEndDate = new Date(year, now.getMonth()+1, days);
    var monthRange = [monthStartDate,monthEndDate];
    return monthRange;
}

function getToday(){
    return formatDate(new Date());
}
function  getTomorrow() {
    var date = new Date();
    date.setDate(date.getDate() + 1);
    return formatDate(date);
}


